﻿using Common;
using IBLL;
using Microsoft.AspNetCore.Mvc;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Unmanned_MSUI.Areas.Admin.Filters;

namespace Unmanned_MSUI.Areas.Admin.Controllers
{
    [Area("Admin")]
    [MyFilter]
    public class OrderInfoController : Controller
    {
        private IOrderInfoBLL _orderInfoBLL;

        public OrderInfoController(
            IOrderInfoBLL orderInfoBLL
            )
        {
            _orderInfoBLL = orderInfoBLL;
        }
        
        public IActionResult ListView()
        {
            return View();
        }
        #region 获取列表的接口(GetDepartmentInfos)

        [HttpGet]
        public IActionResult GetOrderInfos(int page, int limit, string id)
        {
            //声明返回对象
            ReturnResult result = new ReturnResult();
            //声明一个总数的变量
            int count;
            //调用BLL的获取用户方法
            var list = _orderInfoBLL.GetOrderInfos(page, limit, id, out count);
            //返回值
            result.Code = 0;
            result.IsSuccess = true;
            result.Msg = "获取成功！";
            result.Count = count;
            result.Data = list;


            //返回结果
            return Json(result);

        }
        #endregion
        #region 添加订单的方法
        [HttpPost]
        public IActionResult CreateDepartmentInfo([FromForm] OrderInfo orderInfo)
        {
            //实例化返回对象
            ReturnResult result = new ReturnResult();
            //调用添加部门的方法
            string msg;
            result.IsSuccess = _orderInfoBLL.CreateOrderInfo(orderInfo, out msg);
            result.Msg = msg;
            //判断是否添加成功并返回结果
            if (result.IsSuccess)
            {
                result.Code = 200;//修改状态码
            }
            return Json(result);

        }
        #endregion



    }
}
